import { pathExistsSync, readdirSync, removeSync, existsSync } from 'fs-extra'
import { exec } from 'node:child_process'

export const isEmpty = (path: string) => {
  return !(pathExistsSync(path) && readdirSync(path).length !== 0)
}

export const emptyDir = (path: string) => {
  if (!existsSync(path)) return
  removeSync(path)
}

export const execPromise = (...args: Parameters<typeof exec>) => {
  return new Promise((resolve, reject) => {
    const [command, opts] = args;
    exec(command, {
      ...opts,
    }, (error) => {
      if (error) {
        reject(error);
      } else {
        resolve(true);
      }
    });
  });
};

